import java.awt.*;
import java.awt.event.*;
/**
 * Die Welt in der Automaten über N "leben"
 * 
 * @author henry@freye.de
 *
 */
public class WeltN extends Frame implements WindowListener{
	/*
	 * Die Zeichenmethode
	 */
	public void paint(Graphics g){
		System.out.println("Position"+aktorPosition);
		int breite = this.getWidth();
		int hoehe = this.getHeight();
		//System.out.println("paint "+breite+","+hoehe);
		g.setColor(new Color(230,230,230));
		g.fillRect(0, 0, breite, hoehe);
		g.setColor(new Color(0,0,200));
		g.drawLine(20,hoehe-30, breite-20,hoehe-30);	
		
		for (int i=0; i<= max;i++){
			int b = i*(breite-40)/(max)+20;
			g.drawLine(b,hoehe-25,b,hoehe-35);
			g.drawString("0", 12, hoehe-15);
		}
		g.setColor(Color.RED);
		g.drawOval(aktorPosition*(breite-40)/(max)+20-8, hoehe-40, 16, 16);
	}
	
	/**
	 * Damit man die Klasse theoretisch speichern kann
	 */
	private static final long serialVersionUID = -1734249687065243767L;
	private int max;
	private int aktorPosition;

	
	
	/**
	 * @param String title
	 */
	public WeltN(String title){
		super(title);
		this.setSize(500, 80);
		this.setVisible(true);
		this.addWindowListener(this);
		this.max = 10;
		aktorPosition = 0;
	}
	public void setAktor(int pos){
		aktorPosition = pos;
	}
	
	public void gehe(int i){
		if (i==1){
			aktorPosition++;
		}
		if (i==-1 && aktorPosition > 0){
			aktorPosition--;
		}
		this.repaint();
	}

	public int getPosistion(){
		if (aktorPosition > 0){
			return 1;
		}else{
			return 0;
		}
	}
	
	
	/**
	 * @param String title
	 */
	public WeltN(String title, int max){
		this(title);
		this.max = max;
		//System.out.println("Neu: max="+max);
	}

	public void windowActivated(WindowEvent arg0) {	}
	public void windowClosed(WindowEvent arg0) {}
	public void windowClosing(WindowEvent arg0) {
		System.exit(0);
		this.dispose();		
	}
	public void windowDeactivated(WindowEvent arg0) {	}
	public void windowDeiconified(WindowEvent arg0) {	}
	public void windowIconified(WindowEvent arg0) {}
	public void windowOpened(WindowEvent arg0) {}

}
